/**
 *
 */
package com.siteseat.common.exception;

import java.util.Locale;

import com.siteseat.common.i18n.Label;

/**
 */
public class ExternalException extends SSException {

  /**
   *
   */
  private static final long serialVersionUID = -4364360792203065124L;

  private Label             label;

  private Object[]          arguments;

  
  /**
   *
   *
   * @param message
   * @param cause
   */
  public ExternalException( String message, Throwable cause ) {
    super( message, cause );
  }

  /**
   *
   *
   * @param message
   */
  public ExternalException( String message ) {
    super( message );
  }

  /**
   * @param message
   */
  public ExternalException( Label errorLabel, Object... args ) {
    this.label = errorLabel;
    this.arguments = args;
  }

  /**
   * @param message
   * @param cause
   */
  public ExternalException( Throwable cause, Label errorLabel ) {
    this.label = errorLabel;
  }

  /**
   * @param message
   * @param cause
   */
  public ExternalException( Throwable cause, Label errorLabel, Object... args ) {
    this.label = errorLabel;
    this.arguments = args;
  }

  /**
   * 
   */
  public Label getLabel() {
    return this.label;
  }

  /**
   * @return the arguments
   */
  public Object[] getArguments() {
    return arguments;
  }

  /**
   * @param language
   * @return
   */
  public String getMessage( String language ) {
    if( label == null ) {
      return super.getMessage();
    }
    return label.formatMessage( language, getArguments() );
  }

  /**
   * @param language
   * @return
   */
  public String getMessage( Locale locale ) {
    if( label == null ) {
      return super.getMessage();
    }
    return label.formatMessage( locale, getArguments() );
  }

  /*
   * (non-Javadoc)
   * @see java.lang.Throwable#getMessage()
   */
  @Override
  public String getMessage() {
    if( label == null ) {
      return super.getMessage();
    }
    return label.formatDefaultMessage( getArguments() );
  }

}
